package com.xbang.util.voucher.biz;

import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.kdf.table.KDTDefaultCellEditor;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemCollection;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.ui.face.IUIObject;
import com.kingdee.eas.basedata.master.account.client.AccountPromptBox;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.common.client.SysContext;

/**
 * @author lifetime
 * 
 */
public abstract class AccountUtil {

	public static void bindAccountF7(IUIObject owner, KDBizPromptBox f7, CompanyOrgUnitInfo fiOrgUnit) {
		if (fiOrgUnit == null) {
			fiOrgUnit = SysContext.getSysContext().getCurrentFIUnit();
		}
		SelectorItemCollection sic = new SelectorItemCollection();
		sic = new SelectorItemCollection();
		sic.add(new SelectorItemInfo("id"));
		sic.add(new SelectorItemInfo("number"));
		sic.add(new SelectorItemInfo("name"));
		sic.add(new SelectorItemInfo("longName"));
		String companyid = fiOrgUnit.getId().toString();
		FilterInfo filter = new FilterInfo();
		FilterItemCollection fic = filter.getFilterItems();
		fic.add(new FilterItemInfo("companyID.id", companyid));
		fic.add(new FilterItemInfo("accountTableID.id", fiOrgUnit.getAccountTable().getId().toString()));
		filter.setMaskString("#0 and #1");
		AccountPromptBox apb = new AccountPromptBox(owner, fiOrgUnit, filter, false, false);
		f7.setEditable(true);
		f7.setEditFormat("$number$");
		f7.setCommitFormat("$helpCode$;$number$;$name$");
		f7.setDisplayFormat("$number$ - $name$");
		f7.setQueryInfo("com.kingdee.eas.basedata.master.account.app.F7AccountViewQuery");
		f7.setSelector(apb);
		f7.setSelectorCollection(sic);
	}

	public static KDBizPromptBox bindAccountF7Cell(IUIObject owner, KDTable table, String colName, CompanyOrgUnitInfo fiOrgUnit) {
		KDBizPromptBox f7 = new KDBizPromptBox();
		bindAccountF7(owner, f7, fiOrgUnit);
		KDTDefaultCellEditor cellEditor = new KDTDefaultCellEditor(f7);
		table.getColumn(colName).setEditor(cellEditor);
		return f7;
	}
}
